home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / fortn404.zip / FORTUNE.DOC < prev    next >
Text File  |  1994-04-23  |  15KB  |  318 lines

  1. FORTUNE.DOC
  2. 04/23/94
  3.  
  4. The FORTUNE.EXE program adds some tuning features to the DOS FOR command (FOR
  5. tune, fortune, what the heck).  These features can in some way be applied to
  6. commands accepting regular DOS wildcards.  Features include:
  7.  
  8.  * Results of command are written to a batch file which you can review before
  9.    you run it.  Lets you subsequently edit it if desired and lets you see
  10.    exactly what commands will happen when you run it.
  11.  * Ability to imbed redirection indicators in a command (see next example).
  12.  * Ability to separate the file name and file extension.  For example:
  13.         FORTUNE IN (*.TXT) DO SORT %[ %A %] %1*.SOR
  14.  * Ability to identify individual characters in the the file name and extension.
  15.    For example:
  16.         FORTUNE IN (*.TXT) DO RENAME %A (%1%2%3%4%5%6).*
  17.  * Ability to specify a character other than "%" for the delimiter so you can
  18.    avoid worrying about different syntax in batch command vs command line
  19.  * Ability to have batch file pause after each command so results can be
  20.    reviewed.
  21.  * Ability to specify incrementation in the file names.  For example:
  22.         FORTUNE IN (*.TXT) /+2 DO COPY %A %1*.%0001
  23.  * Ability to specify multiple statements on one command line.
  24.  * Ability to process children subdirectories (/S option) at same time.  For
  25.    example:
  26.         FORTUNE IN (\*.TXT) /S DO COPY %A D:\BACKUPS
  27.         FORTUNE *.BAT /S DEL %A
  28.  * Ability to exclude up to 10 file specifications from consideration.
  29.  
  30.  
  31. The DOS FOR command:
  32.  
  33. Quite a few DOS users are unaware of the DOS FOR command.  It allows you to do a
  34. single command over a series of files and provides an easy way to use wildcards
  35. with commands that don't accept them.  For example, if you want to type a number
  36. of files to your screen, you can say something like:
  37.  
  38.         FOR %A IN (*.TXT) DO TYPE %A
  39.  
  40. DOS looks at your IN specification and figures out what file names are covered
  41. by that request.  The request can include path information if desired and can
  42. have multiple specification (e.g.  "...IN (*.TXT \BAT\*.DOC)...").
  43.  
  44. FOR then substitutes the file name itself in for whatever variable you specify
  45. in the first parameter after "FOR" ("%A" here).  This variable is a single
  46. character (A to Z) preceded by a single percent sign (%).  (If FOR is used in a
  47. batch command, you have to use two percent signs (%%) instead.)
  48.  
  49. FOR then looks at the command following the keyword "DO" and executes that
  50. command.  If it finds the variable name in the command, it substitutes the name
  51. of the file for that variable.
  52.  
  53.  
  54. So, in the above example, if you had three *.TXT files--ABLE.TXT, BAKER.TXT,
  55. and CHARLIE.TXT--and you ran the command, it would actually do three commands
  56. for you:
  57.  
  58.         TYPE ABLE.TXT
  59.         TYPE BAKER.TXT
  60.         TYPE CHARLIE.TXT
  61.  
  62. All in all, FOR is a *very* useful command.  There are also some DOS tricks that
  63. you can use to make the command even more useful but, frankly, I always forget
  64. the tricks.  (If someone would like to e-mail them to me, I'll throw them in
  65. here.) In any case, even past the tricks, the FORTUNE command provides even more
  66. features.
  67.  
  68.  
  69. FORTUNE wildcards and special characters:
  70.  
  71. The FORTUNE.EXE program extends the functionality of the DOS FOR command by
  72. providing ways of splitting up the parts of the file name and manipulating the
  73. parts.  For example, someone in my office had a mess of files that had to be
  74. renamed as an open parenthesis, followed by the first six characters of the file
  75. name, followed by a close parenthesis.  Not too terrible to handle with my text
  76. editor but it hadn't occurred to her.  Using FORTUNE, however, it's pretty easy:
  77.  
  78.         FORTUNE IN (*.TXT) DO RENAME %A (%1%2%3%4%5%6).*
  79.  
  80. And then you run the newly-created batch file (DOIT.BAT).
  81.  
  82. Similarly, someone wanted me to rename a mess of files so they had sequential
  83. names.  I had to write a program to handle it.  Definitely beyond his
  84. capabilities.  Again, using FORTUNE it's pretty easy:
  85.  
  86.         FORTUNE IN *.TXT DO RENAME %A %1*.%0001
  87.  
  88. And again you run the DOIT.BAT file.
  89.  
  90. Within the command (DO command), FORTUNE allows you to include a number of
  91. indicators.  The character which indicates that it's a special character is
  92. typically "%" but you can change this with the /VAR=char option in FORTUNE.
  93. (You can also set the default by using the CONFIGWS program.) All of the
  94. examples here use the default /VAR=% setting.
  95.  
  96. NOTE TO 4DOS USERS:  4DOS automatically translates %x characters even if used on
  97. the command line.  As such, 4DOS users *have* to use a different /VAR=x setting
  98. to use FORTUNE.  FORTUNE detects that you are running 4DOS and typically changes
  99. the default /VAR=x to /VAR=@.  This default can be changed by using the CONFIGWS
  100. program.
  101.  
  102.  
  103. In many cases, the indicators are case sensitive; there's a difference between
  104. %p and %P.  Typically, the lowercase variants are cumulative.  %P gives you just
  105. the path whereas %p throws in the drive information too.
  106.  
  107.      %a         translates into the entire file name (begins with drive,
  108.                 colon, \, path, \, file root, ., file extension).
  109.                 Use %R.%E if you want the filename without the drive/path info
  110.      %D         translates into the drive (not followed by :)
  111.      %d         translates into the drive (followed by :)
  112.      %P         translates into path (not preceded or followed by \)
  113.      %p         translates into path (begins with drive, colon, \, path, \)
  114.      %R         translates into file name root
  115.      %r         translates into file name root (begins with drive, colon, \,
  116.                 path, \)
  117.      %E         translates into file name extension
  118.      %e         translates into file name extension (begins with drive, colon,
  119.                 \, path, \, file name root, .)--same as %a
  120.      %1 to %8   characters 1 to 8 in the file name root
  121.      %X to %Z   characters 1 to 3 in file name extension (case insignicant;
  122.                 %X is the same as %x)
  123.  
  124. Standard DOS wildcards are supported within the file name.  So %1* will give you
  125. all characters in the file name root, %2* will give you all characters beginning
  126. with the second character.  "?" is also supported.  Wildcards outside of the
  127. special indicators work as expected ("...DO RENAME %A %1*.%X*" works
  128. identically to "...DO RENAME %A *.*").
  129.  
  130. All other characters in the command string are passed as given.
  131.  
  132.  
  133. Using the above characters, if you have two files C:\AUTOEXEC.BAT and
  134. D:\WAYNE\MYSTUFF.TXT, the various codes above translate as:
  135.  
  136.                 C:\AUTOEXEC.BAT         D:\WAYNE\MYSTUFF.TXT
  137.      %A         C:\AUTOEXEC.BAT         D:\WAYNE\MYSTUFF.TXT
  138.      %D         C                       D
  139.      %d         C:                      D:
  140.      %P         (null)                  WAYNE
  141.      %p         \                       D:\WAYNE\
  142.      %R         AUTOEXEC                MYSTUFF
  143.      %r         C:\AUTOEXEC             D:\WAYNE\MYSTUFF
  144.      %E         BAT                     TXT
  145.      %e         C:\AUTOEXEC.BAT         D:\WAYNE\MYSTUFF.TXT
  146.      %1         A                       M
  147.      %2         U                       Y
  148.      %3         T                       S
  149.      %4         O                       T
  150.      %5         E                       U
  151.      %6         X                       F
  152.      %7         E                       F
  153.      %8         C                       (null)
  154.      %X         B                       T
  155.      %Y         A                       X
  156.      %Z         T                       T
  157.  
  158.  
  159.  
  160. Special translations:
  161.  
  162.      %[         translates into <
  163.      %]         translates into >
  164.      %0nnnn     incrementer field (where "nnnn" is any number of digits;
  165.                 translates into a numeric field which has the same number of
  166.                 digits; the first number will be the value of "nnnn" and
  167.                 subsequent files will be incremented by the value specified in
  168.                 the /+n or /-n parameter (defaults to /+1)
  169.  
  170.  
  171. Syntax:
  172.  
  173.     FORTUNE { IN (set) | IN filespec | /IN (set) | /IN filespec | filespec }
  174.       [ /AS filename ] [ /OV